package com.ruoyi.service.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.service.domain.ServiceCategory;
import com.ruoyi.service.service.IServiceCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 项目分类Controller
 * 
 * @author ZDL
 * @date 2024-10-21
 */
@RestController
@RequestMapping("/service/category")
public class ServiceCategoryController extends BaseController
{
    @Autowired
    private IServiceCategoryService serviceCategoryService;

    /**
     * 查询项目分类列表
     */
    @PreAuthorize("@ss.hasPermi('service:category:list')")
    @GetMapping("/list")
    public TableDataInfo list(ServiceCategory serviceCategory)
    {
        startPage();
        List<ServiceCategory> list = serviceCategoryService.selectServiceCategoryList(serviceCategory);
        return getDataTable(list);
    }

    //@GetMapping("/listTree")
    //public CommonResult listTree(){
    //    //获取所有分类学科
    //    List<ServiceCategory> serviceCategoryList = serviceCategoryService.listWithTree();
    //    return CommonResult.success(serviceCategoryList);
    //}
    /**
     * 导出项目分类列表
     */
    @PreAuthorize("@ss.hasPermi('service:category:export')")
    @Log(title = "项目分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ServiceCategory serviceCategory)
    {
        List<ServiceCategory> list = serviceCategoryService.selectServiceCategoryList(serviceCategory);
        ExcelUtil<ServiceCategory> util = new ExcelUtil<ServiceCategory>(ServiceCategory.class);
        util.exportExcel(response, list, "项目分类数据");
    }

    /**
     * 获取项目分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('service:category:query')")
    @GetMapping(value = "/{categoryId}")
    public AjaxResult getInfo(@PathVariable("categoryId") Long categoryId)
    {
        return success(serviceCategoryService.selectServiceCategoryByCategoryId(categoryId));
    }

    /**
     * 新增项目分类
     */
    @PreAuthorize("@ss.hasPermi('service:category:add')")
    @Log(title = "项目分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ServiceCategory serviceCategory)
    {
        return toAjax(serviceCategoryService.insertServiceCategory(serviceCategory));
    }

    /**
     * 修改项目分类
     */
    @PreAuthorize("@ss.hasPermi('service:category:edit')")
    @Log(title = "项目分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ServiceCategory serviceCategory)
    {
        return toAjax(serviceCategoryService.updateServiceCategory(serviceCategory));
    }

    /**
     * 删除项目分类
     */
    @PreAuthorize("@ss.hasPermi('service:category:remove')")
    @Log(title = "项目分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{categoryIds}")
    public AjaxResult remove(@PathVariable Long[] categoryIds)
    {
        return toAjax(serviceCategoryService.deleteServiceCategoryByCategoryIds(categoryIds));
    }
}
